package com.kaifamiao.datatypes;

// 基本数据类型的强制类型转换
// 1、整数类型的强制类型转换: 舍弃高位，保留低位
// 2、浮点类型的强制类型转换
// 3、浮点类型强转为整数类型
public class Elephant {

    public static void main(String[] args) {
        int first = 0b00000000_01000000_01000000_01000000;
        System.out.println( first );

        // 目标类型 变量名 = (目标类型) 值
        // 舍弃 first 取值的 高16位，保留低16位
        short second = (short)first;
        System.out.println( second );

        // 舍弃 first 取值的 高24位，保留低8位
        byte third = (byte)first;
        System.out.println( third );

        System.out.println( "~ ".repeat( 15 ) );

        double fourth = 3.1415926535897384626;
        System.out.println( fourth );

        float fifth = (float) fourth;
        System.out.println( fifth );

        System.out.println( "~ ".repeat( 15 ) );

        double sixth = 129.99;
        System.out.println( sixth );

        // 舍弃小数点部分后再舍弃整数的高位保留低位
        byte seventh = (byte) sixth;
        System.out.println( seventh );

        System.out.println( "~ ".repeat( 15 ) );

        short s = 9527;
        // short --> char
        char c = (char)s ;

        char ch = '\u55b5';
        // char --> short
        short x = (short)ch;

        char ch1 = 65535 ;
        System.out.println( ch1 );

        char ch2 = (char)65536 ;
        System.out.println( ch2 );

    }

}
